package warm100;

import utils.TreeNode;

public class kthSmallest_230 {
    int cnt = 0, flag = 0, ans = -1;

    public int kthSmallest(TreeNode root, int k) {
        find(root, k);
        return ans;
    }

    public void find(TreeNode root, int k) {
        if (root == null)
            return;
        if (flag == 0)
            find(root.left, k);
        cnt++;
        if (cnt == k) {
            flag = 1;
            ans = root.val;
        }
        if (flag == 0)
            find(root.right, k);
    }

}
